<template>
    <div class="m-user">
        <div class="already-login" v-if="user">
            <span class="login-green">{{user}}</span>
            <nuxt-link to="/logout">退出</nuxt-link>
        </div>
        <div class="un-login" v-else>
            <nuxt-link to="/login" class="login-green">立即登录</nuxt-link>
            <nuxt-link to="/register">注册</nuxt-link>
        </div>
    </div>
</template>

<script>
export default{
    data(){
        return{
            user: ''
        }
    },
    mounted(){
        this.$axios.get('http://127.0.0.1:8082/user/getUser').then((res) => {
            if(res.status === 200 && res.data.code === 0){
                this.user = res.data.username;
            }else{
                this.user = '';
            }
        })
    } 
}
</script>

<style lang="less">

</style>